// 这个模块主要是获取spu模块的数据
import request from '@/utils/request'

// 获取spu列表展示数据  /admin/product/{page}/{limit}   get    page limit category3Id
export const reqSpuList = (page, limit, category3Id) => {
  return request({ url: `/admin/product/${page}/${limit}`, params: { category3Id }, method: 'get' })
}

// 获取某一个SPU基本信息  /admin/product/getSpuById/{spuId}  get
export const reqSpuInfo = (spuId) => {
  return request({ url: `/admin/product/getSpuById/${spuId}`, method: 'get' })
}
// 获取品牌列表数据  /admin/product/baseTrademark/getTrademarkList    get
export const reqGetTrademarkList = () => {
  return request({ url: '/admin/product/baseTrademark/getTrademarkList', method: 'get' })
}
// 获取SPU图片信息  /admin/product/spuImageList/{spuId}  get
export const reqSpuImageList = (spuId) => {
  return request({ url: `/admin/product/spuImageList/${spuId}`, method: 'get' })
}

// 获取平台中全部的销售属性  /admin/product/baseSaleAttrList  get
export const reqBaseSaleAttrList = () => {
  return request({ url: '/admin/product/baseSaleAttrList', method: 'get' })
}

// 修改SPU | 添加SPU信息：对于修改或者添加，携带给服务器参数大致一样，唯一的区别就是携带的参数是否带id
// 接口  /admin/product/updateSpuInfo   post
export const reqAddOrUpdateSpuInfo = (spu) => {
  // 携带参数带有id ----修改spu
  if (spu.id) {
    return request({ url: '/admin/product/updateSpuInfo', method: 'post', data: spu })
  } else {
  // 携带参数不带id ----修改spu
    return request({ url: '/admin/product/saveSpuInfo', method: 'post', data: spu })
  }
}

// 删除某一个 SPU    /admin/product/deleteSpu/{spuId}   delete
export const reqDeleteSpu = (spuId) => {
  return request({ url: `/admin/product/deleteSpu/${spuId}`, method: 'delete' })
}

// 给SPU添加一个SKU实例,通过SPU的id获取SKU信息   /admin/product/getSkuById/{skuId}   get
export const reqGetSkuById = (skuId) => {
  return request({ url: `/admin/product/getSkuById/${skuId}`, method: 'get' })
}

/* ---------------------------------------------Spu里添加Sku----------------------------------------------------- */

//  获取平台属性的数据 /admin/product/attrInfoList/{category1Id}/{category2Id}/{category3Id}    get
export const reqAttrInfoList = (category1Id, category2Id, category3Id) => {
  return request({ url: `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`, method: 'get' })
}

//  获取图片的数据 /admin/product/spuImageList/{spuId}   get
// -----------上面写了该接口----------------------------

// 获取销售属性的数据   /admin/product/spuSaleAttrList/{spuId}  get
export const reqSpuSaleAttrList = (spuId) => {
  return request({ url: `/admin/product/spuSaleAttrList/${spuId}`, method: 'get' })
}

// 添加sku
//  /admin/product/saveSkuInfo  post
export const reqAddSku = (skuInfo) => {
  return request({ url: '/admin/product/saveSkuInfo', method: 'post', data: skuInfo })
}

// 获取sku列表数据的接口
// 查看当前spu全部sku列表 /admin/product/findBySpuId/{spuId}   get
export const reqSkuList = (spuId) => {
  return request({ url: `/admin/product/findBySpuId/${spuId}`, method: 'get' })
}
